package main

import (
    "facecat"
    "fmt"
    "io/ioutil"
)

/*
* 重绘背景的实现方法
* view:视图
* paint:绘图对象
* clipRect:裁剪区域
*/
func OnPaint(view *facecat.FCView, paint *facecat.FCPaint, clipRect facecat.FCRect) {
    if view.ViewName == "Button4" {
        paint.FillRect("rgb(255,0,0)", 0, 0, view.Size.Cx, view.Size.Cy);
    }else{
        facecat.OnPaintDefault(view, paint, clipRect)
    }
}
/*
* 鼠标点击实现方法
* view: 图层
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
* clicks:点击次数
*/
func OnClick(view *facecat.FCView, firstTouch bool, firstPoint facecat.FCPoint, secondTouch bool, secondPoint facecat.FCPoint, clicks int){
    facecat.OnClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)
    if view.ViewName == "Button" {
        fmt.Println(view.Text)
    } else if view.ViewName == "Button2" {
        fmt.Println(view.Text)
    } else if view.ViewName == "Button3"{
        fmt.Println(view.Text)
    } else if view.ViewName == "Button4" {
        fmt.Println(view.Text)
    }
}

var gPaint = facecat.CreatePaint()

func WndProc(hwnd facecat.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
    return facecat.WndProcDefault(gPaint, hwnd, msg, wParam, lParam)
}

func main() {
    gPaint.OnPaint = OnPaint
    gPaint.OnClick = OnClick
    facecat.CreateMainWindow(gPaint, "FaceCat-Go", WndProc)
    xmlStr, _ := ioutil.ReadFile("xml//buttonexample.xml")
    facecat.RenderFaceCat(gPaint, string(xmlStr))
    tabPage := facecat.FindViewByName("TabPage2", gPaint.Views);
    button := facecat.CreateView("button")
    button.Location = facecat.CreatePoint(100, 100)
    button.Size = facecat.CreateSize(100, 20)
    facecat.AddViewToParent(button, tabPage)
    button.Text = "确定"
    facecat.ShowWindow(gPaint)
}